import java.util.BitSet;
import java.util.ArrayList;
import java.util.List;

public class test3 {
    public static void main(String[] args) {
        int max = 20000;
        BitSet primes = sieveOfEratosthenes(max);
        List<Integer> primeList = new ArrayList<>();
        if (max >= 2) {
            primeList.add(2);
        }
        for (int i = 3; i <= max; i += 2) {
            if (primes.get(i)) {
                primeList.add(i);
            }
        }
        int count = 0;
        for (int prime : primeList) {
            System.out.printf("%-6d", prime);
            count++;
            if (count % 5 == 0) {
                System.out.println();
            }
        }
    }
    private static BitSet sieveOfEratosthenes(int max) {
        BitSet isPrime = new BitSet(max + 1);
        if (max >= 2) {
            isPrime.set(2);
        }
        for (int i = 3; i <= max; i += 2) {
            isPrime.set(i);
        }
        for (int p = 3; p <= max / p; p += 2) {
            if (isPrime.get(p)) {
                for (int i = p * p; i <= max; i += 2 * p) {
                    isPrime.clear(i);
                }
            }
        }
        return isPrime;
    }
}